package com.ruoyi.api.activiti.listener;

import com.ruoyi.activiti.service.IProcessService;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.event.*;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component("activitiEventListener")
@Slf4j
public class MyActivitiEventListener implements ActivitiEventListener {
  @Autowired(required = false)
  private RuntimeService runtimeService;
  @Autowired
  private IProcessService processService;

  @Autowired
  private TaskService taskService;

  @Override
  public void onEvent(ActivitiEvent event) {
  if(event.getType() == ActivitiEventType.TASK_ASSIGNED){
      log.error("======TASK_ASSIGNED===="+event.toString());
      ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event;
      TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
      String assignee = taskEntity.getAssignee();//重复发送


  }else if(event.getType() == ActivitiEventType.ACTIVITY_COMPLETED){
      log.error("===ACTIVITY_COMPLETED==="+event.toString());
      ActivitiActivityEvent entityEvent = (ActivitiActivityEvent) event;
      if(entityEvent.getActivityType().toLowerCase().equals("endevent")){

      }
    }
  }

  @Override
  public boolean isFailOnException() {
    return false;
  }
}
